package com.cyt.web.controller.work.site;

import cn.hutool.core.util.StrUtil;
import com.cyt.base.enums.BusinessType;
import com.cyt.base.enums.OperatorType;
import com.cyt.base.model.dto.ReturnResult;
import com.cyt.sys.aspect.BaseLog;
import com.cyt.web.controller.base.BaseController;
import com.cyt.work.site.model.vo.NoticeVo;
import com.cyt.work.site.service.NoticeService;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * 微官网-校园资讯控制层
 *
 * @author rong yuan
 * @date 2019-7-8 15:17:40
 */
@RestController
public class NoticeController extends BaseController {

    @Resource
    private NoticeService noticeService;
    /**
     * 统一跳转
     *
     * @param pageName 页面名称
     * @param applyId 应用id
     * @return ModelAndView
     * @author shengQiang Yu
     * @date 2019-08-28 15:17:40
     */
    @RequestMapping("/work/site/notice/{pageName}")
    public ModelAndView goPage(@PathVariable("pageName") String pageName,String applyId) {
        ModelAndView view = new ModelAndView("/work/site/notice/"+pageName);
        view.addObject("applyId",applyId);
        return view;
    }

    /**
     * 分页查询
     *
     * @param noticeVo 接受参数对象
     * @param page     当前页面
     * @param limit    页面数量
     * @return ReturnResult
     * @author rong yuan
     * @date 2019-7-8 15:17:40
     */
    @BaseLog(module = "微官网", classz = "校园资讯", methods = "分页查询对象", businessType = BusinessType.GET, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/work/site/notice/page", method = RequestMethod.POST)
    public ReturnResult page(NoticeVo noticeVo, int page, int limit) {
        return noticeService.page(noticeVo, page, limit);
    }

    /**
     * 跳转添加或编辑界面
     *
     * @param id 主键
     * @return ReturnResult
     * @author rong yuan
     * @date 2019-7-8 15:17:40
     */
    @BaseLog(module = "微官网", classz = "校园资讯", methods = "跳转添加或编辑界面", businessType = BusinessType.GET, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/work/site/notice/getEdit", method = RequestMethod.GET)
    public ModelAndView getEdit(String id,String applyId) {
        ModelAndView view = new ModelAndView("/work/site/notice/noticeEdit");
        if (StrUtil.isNotEmpty(id)) {
            view.addObject(noticeService.selectByPrimaryKey(id));
        }
        view.addObject("applyId",applyId);
        return view;
    }

    /**
     * 保存或更新
     *
     * @param request  请求对象
     * @param noticeVo 接受参数对象
     * @return ReturnResult
     * @author rong yuan
     * @date 2019-7-8 15:17:40
     */
    @BaseLog(module = "微官网", classz = "校园资讯", methods = "保存或更新对象", businessType = BusinessType.INSERT, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/work/site/notice/addOrUpdate", method = RequestMethod.POST)
    public ReturnResult addOrUpdate(HttpServletRequest request, NoticeVo noticeVo) {
        return noticeService.addOrUpdate(noticeVo, acceptCurrentUser(request));
    }

    /**
     * 根据条件逻辑删除
     *
     * @param request  请求对象
     * @param noticeVo 接受参数对象
     * @return ReturnResult
     * @author rong yuan
     * @date 2019-7-8 15:17:40
     */
    @BaseLog(module = "微官网", classz = "校园资讯", methods = "逻辑删除对象", businessType = BusinessType.UPDATE, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/work/site/notice/remove", method = RequestMethod.GET)
    public ReturnResult remove(HttpServletRequest request, NoticeVo noticeVo) {
        return noticeService.remove(noticeVo, acceptCurrentUser(request));
    }

    /**
     * 根据条件物理删除
     *
     * @param request  请求对象
     * @param noticeVo 接受参数对象
     * @return ReturnResult
     * @author rong yuan
     * @date 2019-7-8 15:17:40
     */
    @BaseLog(module = "微官网", classz = "校园资讯", methods = "物理对象对象", businessType = BusinessType.DELETE, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/work/site/notice/delete", method = RequestMethod.POST)
    public ReturnResult delete(HttpServletRequest request, NoticeVo noticeVo) {
        return noticeService.delete(noticeVo, acceptCurrentUser(request));
    }

    /**
     * 发布/取消发布
     *
     * @param request  请求对象
     * @param noticeVo 接受参数对象
     * @return ReturnResult
     * @author rong yuan
     * @date 2019-7-8 15:17:40
     */
    @BaseLog(module = "微官网", classz = "校园资讯", methods = "发布/取消发布", businessType = BusinessType.UPDATE, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/work/site/notice/updateStatus", method = RequestMethod.POST)
    public ReturnResult updateStatus(HttpServletRequest request, NoticeVo noticeVo) {
        return noticeService.updateStatus(noticeVo, acceptCurrentUser(request));
    }

    /**
     * 校园资讯统计
     *
     * @param noticeVo 接受参数对象
     * @return ReturnResult
     * @author rong yuan
     * @date 2019-7-8 15:17:40
     */
    @BaseLog(module = "微官网", classz = "校园资讯", methods = "校园资讯统计", businessType = BusinessType.GET, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/work/site/notice/statisticsByType", method = RequestMethod.POST)
    public ReturnResult statisticsByType(NoticeVo noticeVo) {
        return noticeService.statisticsByType(noticeVo);
    }
}